package data {
	import composants.ClasseCompo;
	
	import flash.events.IEventDispatcher;
	
	import mx.controls.Alert;

	public class Personnage {
		
		//descriptions du perso
		public var nom:String='';
		public var race:String='';
		public var alignement:String='';
		public var genre:String='';
		public var age:int=0;
		public var categorie:String='';
		public var taille:String='';
		public var poids:String='';
		public var description:String='';
		public var divinite:String='';
		
		public var urlAvatar:String='';
		
		public var experience:int=0;
		
		//caracteristiques
		private var _force:int;
		private var _dexterite:int;
		private var _constitution:int;
		private var _intelligence:int;
		private var _sagesse:int;
		private var _charisme:int;
		
		[Bindable]
		private var _modif_force:int;
		[Bindable]
		private var _modif_dexterite:int;
		[Bindable]
		private var _modif_constitution:int;
		[Bindable]
		private var _modif_intelligence:int;
		[Bindable]
		private var _modif_sagesse:int;
		[Bindable]
		private var _modif_charisme:int;
		
		//carac temporaires
		private var _force_temp:int;
		private var _dexterite_temp:int;
		private var _constitution_temp:int;
		private var _intelligence_temp:int;
		private var _sagesse_temp:int;
		private var _charisme_temp:int;
		
		private var _modif_force_temp:int;
		private var _modif_dexterite_temp:int;
		private var _modif_constitution_temp:int;
		private var _modif_intelligence_temp:int;
		private var _modif_sagesse_temp:int;
		private var _modif_charisme_temp:int;
		
		//jet sauvegarde
		public var base_reflexe:int;
		public var base_volonte:int;
		public var base_vigueur:int;
		
		public var bonus_reflexe:int;
		public var bonus_volonte:int;
		public var bonus_vigueur:int;
		
		//resistances diverses
		public var bonusResistance:String;
		
		//CA
		public var ca_armor:int;
		public var ca_bonus:int;
		
		//PV 
		public var pvMax:int;
		
		//intiative
		public var initiative_bonus:int;
		
		//classes
		private var listeClasse:Array=new Array();
		
		//armes
		private var listeArmesMelee:Array=new Array();
		private var listeArmesDistance:Array=new Array();
		
		//munitions
		private var listeMunitions:Array=new Array();
		
		//armures
		private var listeArmures:Array=new Array();
		
		public function Personnage() {
			this.listeClasse.push(new ClasseData());
			this.listeArmesMelee.push(new WeaponData(WeaponData.MELEE));
			this.listeArmesDistance.push(new WeaponData(WeaponData.DISTANCE));
			this.listeArmures.push(new ArmorData());
		}
		
		//classes
		public function getClasseAt(index:int) : ClasseData {
			return this.listeClasse[index];
		}
		
		public function popClasse() : ClasseData {
			if(this.listeClasse.length==1) return null;
			return this.listeClasse.pop();
		}
		
		public function addClasse(classe:ClasseData) : void {
			this.listeClasse.push(classe);
		}
		
		//melée
		public function getMeleeWeaponAt(index:int) : WeaponData {
			return this.listeArmesMelee[index];
		}
		
		public function popMeleeWeapon() : WeaponData {
			if(this.listeArmesMelee.length==1) return null;
			return this.listeArmesMelee.pop();
		}
		
		public function addMeleeWeapon(weapon:WeaponData) : void {
			this.listeArmesMelee.push(weapon);
		}
		
		//distance
		public function getDistanceWeaponAt(index:int) : WeaponData {
			return this.listeArmesDistance[index];
		}
		
		public function popDistanceWeapon() : WeaponData {
			if(this.listeArmesDistance.length==1) return null;
			return this.listeArmesDistance.pop();
		}
		
		public function addDistanceWeapon(weapon:WeaponData) : void {
			this.listeArmesDistance.push(weapon);
		}
		
		//armures
		public function getArmureAt(index:int) : ArmorData {
			return this.listeArmures[index];
		}
		
		public function popArmure() : ArmorData {
			if(this.listeArmures.length==1) return null;
			return this.listeArmures.pop();
		}
		
		public function addArmure(armor:ArmorData) : void {
			this.listeArmures.push(armor);
		}
		
		//munitions
		public function getMunitionAt(index:int) : MunitionData {
			return this.listeMunitions[index];
		}
		
		public function popMunition() : MunitionData {
			if(this.listeMunitions.length==1) return null;
			return this.listeMunitions.pop();
		}
		
		public function addMunition(mun:MunitionData) : void {
			this.listeMunitions.push(mun);
		}
		
		//calculs
		public function calculerValeurCA() : int {
			return 10+this.ca_armor+this.ca_bonus+this.modif_dexterite;
		}
		
		public function calculerValeurInitiative() : int {
			return this.initiative_bonus+this.modif_dexterite;
		}
		
		public function calculerValeurReflexe() : int {
			return this.base_reflexe+this.modif_dexterite+this.bonus_reflexe;
		}
		
		public function calculerValeurVolonte() : int {
			return this.base_volonte+this.modif_sagesse+this.bonus_volonte;
		}
		
		public function calculerValeurVigueur() : int {
			return this.base_vigueur+this.modif_constitution+this.bonus_vigueur;
		}
		
		private function getModif(carac:int) : int {
			var mod:Number=(Number(carac)-10)/2;
			if(mod>0) return Math.floor(mod);
			else return -Math.floor(Math.abs(mod));
		}
		
		public function get charisme_temp():int
		{
			return _charisme_temp;
		}

		public function set charisme_temp(value:int):void
		{
			_charisme_temp = value;
			this._modif_charisme_temp=this.getModif(value);
		}

		public function get sagesse_temp():int
		{
			return _sagesse_temp;
		}

		public function set sagesse_temp(value:int):void
		{
			_sagesse_temp = value;
			this._modif_sagesse_temp=this.getModif(value);
		}

		public function get intelligence_temp():int
		{
			return _intelligence_temp;
		}

		public function set intelligence_temp(value:int):void
		{
			_intelligence_temp = value;
			this._modif_intelligence_temp=this.getModif(value);
		}

		public function get constitution_temp():int
		{
			return _constitution_temp;
		}

		public function set constitution_temp(value:int):void
		{
			_constitution_temp = value;
			this._modif_constitution_temp=this.getModif(value);
		}

		public function get dexterite_temp():int
		{
			return _dexterite_temp;
		}

		public function set dexterite_temp(value:int):void
		{
			_dexterite_temp = value;
			this._modif_dexterite_temp=this.getModif(value);
		}

		public function get force_temp():int
		{
			return _force_temp;
		}

		public function set force_temp(value:int):void
		{
			_force_temp = value;
			this._modif_force_temp=this.getModif(value);
		}

		public function get charisme():int
		{
			return _charisme;
		}

		public function set charisme(value:int):void
		{
			_charisme = value;
			this._modif_charisme=this.getModif(value);
		}

		public function get sagesse():int
		{
			return _sagesse;
		}

		public function set sagesse(value:int):void
		{
			_sagesse = value;
			this._modif_sagesse=this.getModif(value);
		}

		public function get intelligence():int
		{
			return _intelligence;
		}

		public function set intelligence(value:int):void
		{
			_intelligence = value;
			this._modif_intelligence=this.getModif(value);
		}

		public function get constitution():int
		{
			return _constitution;
		}

		public function set constitution(value:int):void
		{
			_constitution = value;
			this._modif_constitution=this.getModif(value);
		}

		public function get dexterite():int
		{
			return _dexterite;
		}

		public function set dexterite(value:int):void
		{
			_dexterite = value;
			this._modif_dexterite=this.getModif(value);
		}

		public function get force():int
		{
			return _force;
		}

		public function set force(value:int):void
		{
			_force = value;
			this._modif_force=this.getModif(value);
			
		}

		public function get modif_charisme_temp():int
		{
			return _modif_charisme_temp;
		}

		public function get modif_sagesse_temp():int
		{
			return _modif_sagesse_temp;
		}

		public function get modif_intelligence_temp():int
		{
			return _modif_intelligence_temp;
		}

		public function get modif_constitution_temp():int
		{
			return _modif_constitution_temp;
		}

		public function get modif_force_temp():int
		{
			return _modif_force_temp;
		}
		
		public function get modif_dexterite_temp():int
		{
			return _modif_dexterite_temp;
		}

		public function get modif_charisme():int
		{
			return _modif_charisme;
		}

		public function get modif_sagesse():int
		{
			return _modif_sagesse;
		}

		public function get modif_intelligence():int
		{
			return _modif_intelligence;
		}

		public function get modif_constitution():int
		{
			return _modif_constitution;
		}

		public function get modif_force():int
		{
			return _modif_force;
		}

		public function get modif_dexterite():int
		{
			return _modif_dexterite;
		}

		public function toString() :String {
			var string:String = 'Personnage:'+
				'\n\n nom: '+this.nom+
				'\n race: '+this.race+
				'\n alignement: '+this.alignement+
				'\n genre: '+this.genre+
				'\n age: '+this.age+
				'\n categorie: '+this.categorie+
				'\n taille: '+this.taille+
				'\n poids: '+this.poids+
				'\n description: '+this.description+
				'\n divinite: '+this.divinite+
				'\n urlAvatar: '+this.urlAvatar+
				'\n experience: '+this.experience+'\n'+
				'\n force: '+this._force+
				'\n dexterite: '+this._dexterite+
				'\n constitution: '+this._constitution+
				'\n intelligence: '+this._intelligence+
				'\n sagesse: '+this._sagesse+
				'\n charisme: '+this._charisme;	
			
			string+='\n\nClasses:'
			for(var i:int=0; i<this.listeClasse.length; i++) string+='\n'+ClasseData(this.listeClasse[i]).toString();
			
			string+='\n\nArmes de mélée:'
			for(var i:int=0; i<this.listeArmesMelee.length; i++) string+='\n'+WeaponData(this.listeArmesMelee[i]).toString();
			
			string+='\n\nArmes de distance:'
			for(var i:int=0; i<this.listeArmesDistance.length; i++) string+='\n'+WeaponData(this.listeArmesDistance[i]).toString();
			
			string+='\n\nArmures:'
			for(var i:int=0; i<this.listeArmures.length; i++) string+='\n'+ArmorData(this.listeArmures[i]).toString();
			return string;
			
		}
	}
}